﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FixEd.Parsers;

namespace FixEd
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            FileForm ff = new FileForm();
            ff.MdiParent = this;
            ff.Show();
            ParserManager.LoadParsers();
            foreach (IParser item in ParserManager.AvailableParsers.Values)
            {
                ToolStripMenuItem tmi = new ToolStripMenuItem
                {
                    Text = item.Name,
                    Tag = item.ID,
                    ToolTipText = item.Description,
                };

                tmi.Click += importToolStripMenuItem_Click;
                importToolStripMenuItem.DropDownItems.Add(tmi);
            }
        }

        /// <summary>
        /// Used to import a document into a NEW window
        /// </summary>
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem psr = (ToolStripMenuItem)sender;
            Guid id;
            Guid.TryParse(psr.Tag.ToString(), out id);
            DataSet ds = ParserManager.OnParseFile(id);
            DataGridView dgv = (DataGridView) MdiChildren[0].ActiveMdiChild.Controls["DgvDocument"];
            dgv.DataSource = ds.Tables[0].DefaultView;
        }


    }
}
